package com.itheima.controller;

import com.itheima.dto.Page;
import com.itheima.dto.RoleDTO;
import com.itheima.result.PageData;
import com.itheima.result.R;
import com.itheima.service.SysRoleService;
import com.itheima.vo.RoleAuthListVO;
import com.itheima.vo.RoleVO;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @projectName: kafka
 * @package: com.itheima.controller
 * @className: SysRoleController
 * @author: Eric
 * @description: TODO
 * @date: 2023/9/21 18:52
 * @version: 1.0
 */
@Slf4j
@RestController
@RequestMapping("/sys_role")
@AllArgsConstructor
public class SysRoleController {
    private final SysRoleService sysRoleService;

    /**
     * 页面查询角色
     *
     * @param page 页面
     * @return {@link R}<{@link PageData}>
     */
    @GetMapping("/list")
    public R<PageData> pageQueryRole(Page page){
        PageData pageData = sysRoleService.pageQueryRole(page);
        return R.success(pageData);
    }

    /**
     * 查询所有角色
     *
     * @return {@link R}<{@link List}<{@link RoleVO}>>
     */
    @GetMapping("/allData")
    public R<List<RoleVO>> queryAllRoles(){
        List<RoleVO> roleVOList = sysRoleService.queryAllRoles();
        return R.success(roleVOList);
    }

    /**
     * 创造角色
     *
     * @param roleDTO 角色d去
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/add")
    public R<?> creatRole(@RequestBody RoleDTO roleDTO){
        sysRoleService.creatRole(roleDTO);
        return R.success();
    }

    /**
     * 查询角色
     *
     * @param id id
     * @return {@link R}
     */
    @GetMapping("/rowInfo")
    public R<RoleAuthListVO> queryRole(String id){
        RoleAuthListVO roleAuthListVO = sysRoleService.queryRole(id);
        return R.success(roleAuthListVO);
    }

    /**
     * 删除角色
     *
     * @param id id
     * @return {@link R}<{@link ?}>
     */
    @GetMapping("/del")
    public R<?> deleteRole(String id){
        sysRoleService.deleteRole(id);
        return R.success();
    }

    /**
     * 更新角色
     *
     * @return {@link R}<{@link ?}>
     */
    @PostMapping("/update")
    public R<?> updateRole(@RequestBody RoleDTO roleDTO){
        sysRoleService.updateRole(roleDTO);
        return R.success();
    }

}
